/**
 * 
 */
package org.seginfo.httpfuzzer.header.impl;

import org.seginfo.httpfuzzer.header.AttackStrategy;
import org.seginfo.httpfuzzer.header.HeaderPropertyImpl;

/**
 * @author Administrador
 *
 */
public class IfModifiedSince extends HeaderPropertyImpl {
	
	private static final String NAME = "If-Modified-Since";
	private static final String VALID = "Sat, 29 Oct 1994 19:43:31 GMT";
	//private static final String WILDCARD = "*/*";
	private static final int BAD_STRING_MIN_LENGTH = 8;
	private static final int BAD_STRING_LENGTH = 2000;

	/**
	 * @param attackStrategy
	 */
	public IfModifiedSince(AttackStrategy attackStrategy) {
		super(attackStrategy);
		this.value = this.generateValue();
	}

	/**
	 * @see org.seginfo.httpfuzzer.header.HeaderPropertyImpl#getName()
	 */
	public String getName() {
		return NAME;
	}

	/**
	 * @return
	 */
	private String generateValue() {
		
		String rv;

		double p = Math.random();
		if (p < 0.05) {
			// Good date
			rv = VALID;
		} else if (p < 0.10) {
			// Too old date
			rv = "Sat, 29 Oct 1214 19:43:31 GMT";
		} else if (p < 0.15) {
			// Non-exist date
			rv = "Sat, 29 Feb 2007 19:43:31 GMT";
		} else if (p < 0.20) {
			// Error date
			rv = "text/html";
		} else	{ 
			rv = attackStrategy.getStringAttack(BAD_STRING_MIN_LENGTH, BAD_STRING_LENGTH);
		}

		return rv;
	}
}
